angular.module('forget', [])
    .controller('forgetCtrl', ['$scope', 'httpService', '$state', '$stateParams', 'alertmsg', '$location', function($scope, httpService, $state, $stateParams, alertmsg, $location) {
        $scope.data = {};
        if($stateParams.data) {
            $scope.data = JSON.parse($stateParams.data);
        }
        
        if($location.search().code) {
            $scope.data.code = $location.search().code;
        }
        // 忘记密码
        // type: email 	邮箱用户
        // type: tel 	手机用户
        var firstsubmit = true;
        $scope.isforget = false;
        $scope.forget = function(bool, data) {
            if (firstsubmit) {
                if(!bool) {
                    firstsubmit = false;
                    data.code = data.code + '';
                    httpService.query('web/reset', data, 'post').then(function(res) {
                        firstsubmit = true;
                        if (res.code == 200) {
                            $state.go('login');
                        } else {
                            alertmsg(res.msg);
                        }
                    }, function() {
                        firstsubmit = true;
                    });
                } else {
                    $scope.isforget = true;
                }
                    
            } else {
                alertmsg('请不要多次提交！');
            }
        };


    }]);
